package com.lixinyue.test09;

import java.util.Arrays;
import java.util.Comparator;
import java.util.jar.JarOutputStream;

/**
 * @program: 11.12
 * @description:
 * @author: 李鑫月
 * @create: 2021-11-16 20:50
 **/
//class Student implements Comparable<Student>{
//    public int age;
//    public String name;
//    public double score;
//
//    public Student(int age, String name, double score) {
//        this.age = age;
//        this.name = name;
//        this.score = score;
//    }
//
//    @Override
//    public String toString() {
//        return "Student{" +
//                "age=" + age +
//                ", name='" + name + '\'' +
//                ", score=" + score +
//                '}';
//    }
//
////谁调用这个方法谁就是this
//    @Override
//    public int compareTo(Student o) {
////        if(this.age>o.age){
////            return 1;
////        }else if(this.age==o.age){
////            return 0;
////        }else {
////            return -1;
////        }
//        return this.age-o.age;
//       // return name.compareTo(o.name);
//    }
//}

class Student{
    public int age;
    public String name;
    public double score;

    public Student(int age, String name, double score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }


}
class AgeComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}
class ScoreComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return (int )(o1.score-o2.score);
    }
}
class NameComparator implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
public class Test {
    public static void main4(String[] args) {
        Student students1=new Student(121,"zang",88.3);
       Student students2=new Student(161,"zdfng",83.3);
    AgeComparator ageComparator=new AgeComparator();
        System.out.println(ageComparator.compare(students1,students2));
    }
//    public static void main2(String[] args) {
//        Student students1=new Student(121,"zang",88.3);
//        Student students2=new Student(16,"zdfng",83.3);
//
//        System.out.println(students1.compareTo(students2));
//    }
    public static void main(String[] args) {
    Student[] students=new Student[3];
    students[0]=new Student(12,"zang",88.3);
    students[1]=new Student(162,"zdfng",83.3);
    students[2]=new Student(123,"cgang",58.3);
        System.out.println(Arrays.toString(students));
        AgeComparator ageComparator=new AgeComparator();
        Arrays.sort(students,ageComparator);
        System.out.println(Arrays.toString(students));
        ScoreComparator scoreComparator=new ScoreComparator();
        Arrays.sort(students,scoreComparator);
        System.out.println(Arrays.toString(students));
        NameComparator nameComparator=new NameComparator();
        Arrays.sort(students,nameComparator);
        System.out.println(Arrays.toString(students));

    }
//    public static void main1(String[] args) {
//        int [] arr={1,2,2,32,45,5,6};
//        System.out.println(Arrays.toString(arr));
//        Arrays.sort(arr);
//        System.out.println(Arrays.toString(arr));
//    }
}
